04. Local Notifications

Local Notifications

Introduction to Local Notifications

When dealing with notifications, it's important to understand that there are two different types: push notifications, and local notifications.

Local notifications do not use or require any external infrastructure; they happen entirely on the device itself. That means that the only requirement for the device to display the notification is that the device is on. On the other hand, push notifications require you to have a server which handles pushing the notification to your user's devices when a certain event occurs.

But since we're not incorporating an external server, and all the logic about when we should show the notification can be done on the phone itself -- local notifications will be the most ideal for our application. Let's see how it's done!

⚠️ Notifications on iOS ⚠️

Before we jump in, note that with iOS, notifications (both push notifications and local notifications) do not appear at the top of the screen automatically if the application is in the foreground. Moreover, push notifications do not function in the iOS simulator (whether or not Expo is used).

For more information, check out this post in the Expo forums. This issue does not appear when working with notifications on Android.

SetLocalNotification

⚠️ scheduleLocalNotificationAsync ⚠️

In the previous video, scheduleLocalNotificationAsync should have been used instead of the erroneous scheduleLocalNotificationsAsync (note that "Notification" is pluralized in the incorrect version).

The following commit contains the correct version in helpers.js. For additional information, feel free to check out this article in the Expo documentation.

UseLocalNotification

What's the API for scheduling future local notifications with Expo?

SOLUTION:
  • `Notifications.scheduleLocalNotificationAsync`

Task Description:

Almost there! How did local notifications go?

Task List:

Task Feedback:

Fantastic!

Summary

In this section, you learned how to add local notifications to your app using Expo's Notifications property. For further reading, you can visit the official documentation.